<?php
$home_title = "";
$title = "Welcome";
$page_name = array();
$page1_title = array();
$page1_img = array();
$page1_url = array();

$page2_title = array();
$page2_img = array();
$page2_url = array();

function getConfig($filename){

  global $home_title,$title ,$page_name,$page1_title,$page1_img,$page1_url,$page2_title,$page2_img,$page2_url;

  if (file_exists($filename)) {
    $file = fopen($filename, "r");
    $user = array();
    while (!feof($file)) {
      $str = fgets($file); //fgets()函数从文件指针中读取一行
      $str = trim($str);
      if ($str!='' && $str[0] == '#') continue;
  
      $array = explode("=", $str,2); //转换成数组
      if (count($array) >= 2) {
        switch ($array[0]) {
          case 'home':
            $home_title = $array[1];
            break;
          case 'title':
            $title = $array[1];
            break;
          case 'page':
            $page_name = explode(";", $array[1]); //转换成数组
            break;
          case 'page1':
            $p1_array = explode(";", $array[1]); //转换成数组
            if (count($p1_array) >= 3) {
              $page1_title[] = trim($p1_array[0]);
              $page1_img[] = trim($p1_array[1]);
              $page1_url[] = trim($p1_array[2]);
            }
            break;
          case 'page2':
            $p2_array = explode(";", $array[1]); //转换成数组
            if (count($p2_array) >= 3) {
              $page2_title[] = trim($p2_array[0]);
              $page2_img[] = trim($p2_array[1]);
              $page2_url[] = trim($p2_array[2]);
            }
            break;
        }
      }
    }
    fclose($file);
}

}
